﻿//public class Person
//{
//    public string Name { get; set; }
//    public int Age { get; set; }
//}

//public class Program
//{
//    public int GetMaxArea(List<int> list)
//    {
//        int left = 0;
//        int right = list.Length - 1;
//        int res = int.MinValue;
//        int tmpV = 0;
//        while(left < right)
//        {
//            tmpV = Math.Min(list[left], list[right]) * (right-left);
//            res = Math.Max(res, tmpV);

//            if (list[left] < list[right])
//            {
//                left++;
//            }
//            else
//            {
//                right--;   
//            }
//        }
//        return res;
//    }

//    //public static void Main()
//    //{
//    //    List<Person> persons = new List<Person>
//    //    {
//    //        new Person { Name = "A", Age = 20 },
//    //        new Person { Name = "B", Age = 25 },
//    //        new Person { Name = "C", Age = 30 }
//    //    };

//    //    var p = persons.FirstOrDefault(p => p.Age == 25);

//    //    if (p != null)
//    //    {
//    //        Console.WriteLine($"{p.Name},{p.Age}");
//    //    }
//    //}
//}

using System;

public class TreeNode
{
    public int Value;
    public TreeNode Left;
    public TreeNode Right;

    public TreeNode(int value)
    {
        Value = value;
        Left = null;
        Right = null;
    }
}

public class Tree
{
    public TreeNode Root;

    public Tree(int rootValue)
    {
        Root = new TreeNode(rootValue);
    }

    public bool Compare(Tree oTree)
    {
        if (Root == null && oTree.Root == null)
        {
            return true;
        }

        if (Root == null || oTree.Root == null)
        {
            return false;
        }

        return (Root.Value == oTree.Root.Value) &&
               Compare(Root.Left, oTree.Root.Left) &&
               Compare(Root.Right, oTree.Root.Right);
    }

    private bool Compare(TreeNode node1, TreeNode node2)
    {
        if (node1 == null && node2 == null)
        {
            return true;
        }

        if (node1 == null || node2 == null)
        {
            return false;
        }

        return (node1.Value == node2.Value) &&
               Compare(node1.Left, node2.Left) &&
               Compare(node1.Right, node2.Right);
    }
}

public class Program
{
    public static void BubbleSort(int[] arr)
    {
        int n = arr.Length;
        for (int i = 0; i < n - 1; i++)
        {
            for (int j = 0; j < n - 1 - i; j++)
            {
                if (arr[j] > arr[j + 1])
                {
                    int tmp = arr[j];
                    arr[j] = arr[j + 1];
                    arr[j + 1] = tmp;
                }
            }
        }
    }
    void InsertSort(int[] arr)
    {
        for (int i = 0; i < n - 1; i++)
        {
            int end = i;
            int tmp = arr[end + 1];
            while (end >= 0)
            {
                if (tmp < arr[end])
                {
                    arr[end + 1] = arr[end];
                    end--;
                }
                else
                {
                    break;
                }
            }
            arr[end + 1] = tmp;
            
        }
    }

    public static void Swap<T>(ref T a, ref T b)
    {
        T t = a;
        a = b;
        b = t;
    }

    void SelectSort(int[] a)
    {
        int begin = 0, end = a.Length - 1;
        while (begin < end)
        {
            int minnum = begin, maxnum = begin;
            for (int i = begin + 1; i <= end; i++)
            {
                if (a[i] < a[minnum])
                {
                    minnum = i;
                }
                if (a[i] > a[maxnum])
                {
                    maxnum = i;
                }
            }
            int temp = a[minIndex];
            a[minIndex] = a[i];
            a[i] = temp;

            if (maxnum == begin)
            {
                maxnum = minnum;
            }
            intemp = a[minIndex];
            a[minIndex] = array[i];
            a[i] = temp;
            end--;
            begin++;
        }

        public static void Main()
    {
        //Tree tree1 = new Tree(1);
        //tree1.Root.Left = new TreeNode(2);
        //tree1.Root.Right = new TreeNode(3);

        //Tree tree2 = new Tree(1);
        //tree2.Root.Left = new TreeNode(2);
        //tree2.Root.Right = new TreeNode(3);

        //bool areEqual = tree1.Compare(tree2);
        //Console.WriteLine("Are the trees equal? " + areEqual);

        int[] nums = [5, 2, 3, 1];
        BubbleSort(nums);
    }
}